package org.csmzxy.class2334;

class Animal2{
    public void speak(){
        System.out.println("动物发出叫声");
    }
}
class Cat2 extends Animal2{
    @Override
    public void speak() {
        System.out.println("小猫：喵喵");
    }
}
class Dog2 extends Animal2{
    @Override
    public void speak() {
        System.out.println("小狗：汪汪");
    }
    public void houseKeep(){
        System.out.println("狗狗会看家");
    }
}
public class Example15 {
    public static void main(String[] args){
        Animal2 animal =new Cat2();
        if(animal instanceof Dog2){
            Dog2 dog =(Dog2) animal;
            dog.houseKeep();
        }else{
            System.out.println("对象类型向下转换不合法");
        }
    }
}
